package com.example.ql.express.utils.operate;

import com.example.ql.express.model.vo.ScriptConfigVO;
import com.example.ql.express.utils.CommonAppendUtils;

import static com.example.ql.express.model.enums.AppendRuleEnum.END;
import static com.example.ql.express.model.enums.AppendRuleEnum.FIRST;

/**
 * @author xuweizhi
 * @since 2021/10/28 17:38
 */
public class CommonOperateCompare implements OperateCompare {


    @Override
    public String generateCompareRule(ScriptConfigVO scriptConfig) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(String.format(FIRST.getContent(), CommonAppendUtils.nullPointAppend(scriptConfig.getValidateRule(), true)));
        // 替换值有问题
        String compareRule = scriptConfig.getCompareRule();
        for (String level : scriptConfig.getLevels()) {
            compareRule = compareRule.replaceFirst("#\\{level}", level + "");
        }
        stringBuilder.append(compareRule);
        stringBuilder.append(END.getContent());
        return stringBuilder.toString();
    }
}
